package cn.jsu.oj.judgment.thread;


import cn.jsu.oj.judgment.pojo.RealTaskInfo;
import cn.jsu.oj.judgment.pojo.TaskInfo;
import cn.jsu.oj.judgment.process.Handle.JudgeUnixDomainHandler;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import static cn.jsu.oj.judgment.config.DataStructureConfig.sendBoxApplyQueue;
import static cn.jsu.oj.judgment.config.DataStructureConfig.taskQueue;



@Slf4j
public class SendBoxApplyThread implements Runnable{

    @Override
    public void run() {
        while(true) {
            try {
                //前置条件
                sendBoxApplyQueue.take();
                TaskInfo taskInfo = taskQueue.take();
//                log.info("沙箱成功申请判题任务，任务剩余数量{}",taskQueue.size());
                RealTaskInfo realTaskInfo = new RealTaskInfo();
                BeanUtils.copyProperties(taskInfo,realTaskInfo);
                realTaskInfo.setsubjectId(taskInfo.getSubjectId());
                JudgeUnixDomainHandler.channel.writeAndFlush(realTaskInfo.serialize());
            } catch (Exception e) {
                log.error(e.getLocalizedMessage(),e);
            }
        }
    }
}
